import { ref } from "@vue/composition-api";
import { toJSON } from "../utils/commons";
import { request } from "../utils/request";

export const useCompanyData = id => {
  const loading = ref(true);
  const data = ref({});

  async function fetch() {
    const res = await request("cedar-system/enterprise/detail", {
      params: { id }
    });

    data.value = {
      ...res,
      originalName: toJSON(res.originalName, []).join("，")
    };

    loading.value = false;
  }

  fetch();

  return { loading, data };
};
